﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BrokerBase.Lib.Policy;
using BrokerBase.Lib.Product;

namespace broker.duty.ZYRS
{
    class Class1
    {
        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.SchemePeriodActing.InsurantStates.Contains("身故") || ppa.SchemePeriodActing.InsurantStates.Contains("意外身故"))
            {
                double tmp = ppa.TotalFee;
                const double max = 300000;

               

                if (ppa.SchemePeriodActing.InsurantStates.Contains("意外身故") && ppa.Age >= 18)
                {
                    
                    tmp += ppa.Amount * 18;
                }

                da.Value = tmp > max ? max : tmp;

                ppa.IsCurrentFinish = true;
            }

        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {


            if (ppa.Period > 0 && ppa.PolicyActing.PeriodActings[ppa.Period - 1].SchemePeriodActing.InsurantStates.Contains("全残"))
            {
                ppa.Fee = 0;
            }

        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.Period > 0)
            {
                double f = (double)ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("分红率(预估)");

                ppa.Amount += ppa.PolicyActing.PeriodActings[ppa.Period - 1].Amount * f;
            }


            if (ppa.IsLastPeriod)
            {
                da.Value = ppa.Amount;
            }

        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.SchemePeriodActing.InsurantStates.Contains("身故") || ppa.SchemePeriodActing.InsurantStates.Contains("意外身故"))
            {
                string a = ppa.PolicyActing.Policy.SelectedColRateFactors["领取年龄"];
                int receiveAge = int.Parse(a.Substring(0, 2));
                const double max = 300000;

                double tmp = 0;

                if (ppa.Age >= receiveAge)
                {
                    
                    tmp = (88 - ppa.Age) * ppa.Amount * 12 + ppa.Amount * 88;
                }
                else
                {
                    tmp = ppa.TotalFee;
                }

                if (ppa.SchemePeriodActing.InsurantStates.Contains("意外身故") && ppa.Age >= 18 && ppa.Age<receiveAge)
                {
                    double tmp2 = ppa.Amount * 300;

                    tmp += tmp2 > max ? max : tmp2;
                }

                da.Value = tmp;

                ppa.IsCurrentFinish = true;
            }

        }
    }
}
